package com.zmn.mcc.admin.controller.staff.securitylog;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.mcc.model.entity.staff.securitylog.StaffSecurityLog;
import com.zmn.mcc.model.entity.staff.securitylog.StaffSecurityLogQuery;
import com.zmn.mcc.model.vo.StaffSecurityLogVo;
import com.zmn.mcc.services.interfaces.staff.securitylog.StaffSecurityLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * 员工安全日志表基础查询Controller
 *
 * @author tanghongjun
 * @since 2020-06-20 14:17:03
 */
@RestController
@RequestMapping("/staff/staffsecuritylog/")
public class StaffSecurityLogListController extends StaffSecurityLogBaseController {

    private Logger logger = LoggerFactory.getLogger(StaffSecurityLogListController.class);

    @Resource
    private StaffSecurityLogService staffSecurityLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("staff/staffsecuritylog/list.action")
    public ModelAndView list(@ModelAttribute StaffSecurityLogQuery query) {

        if (NumberUtil.isNullOrZero(query.getStaffId())) {
            query.setStaffId(getLoginStaff().getStaffId());
        }

        if (StringUtil.isNotBlank(query.getCreateTimeRange())) {
            String[] createTimeRangeArray = query.getCreateTimeRange().split("-");
            query.setCreateTimeStart(createTimeRangeArray[0].trim() + " 00:00:00");
            query.setCreateTimeEnd(createTimeRangeArray[1].trim() + " 23:59:59");
        }

        List<StaffSecurityLogVo> items = staffSecurityLogService.listPageByQuery(query);

        ModelAndView mav = new ModelAndView("staff/securitylog/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);

        return mav;
    }

}
